import 'package:after_sale_plugin/package_event.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cached_pdfview/flutter_cached_pdfview.dart';
import 'package:lx_widgets_library/lx_widgets_library.dart';

import 'controller.dart';

class PdfPreviewView extends BaseGetView<PdfPreviewController> {
  @override
  String get title => controller.state.pdfPreviewArguments.value.navTitle;

  @override
  Color? get barBackgroundColor => Colors.black;

  @override
  Widget? get backView => CommonWidgets.appBarLeading();

  @override
  Widget buildBody(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false,
      body: PDF(
        enableSwipe: true,
        swipeHorizontal: false,
        autoSpacing: false,
        pageFling: false,
        backgroundColor: Colors.grey,
        onError: (error) {
          PackageEvent.showToast(error.toString());
        },
        onPageError: (page, error) {
          PackageEvent.showToast(error.toString());
        },
        onPageChanged: (page, total) {},
      ).fromUrl(controller.state.pdfPreviewArguments.value.path),
    );
  }
}
